﻿@{ Layout = "~/Views/Shared/_ModalForm.cshtml";
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <input id="isDefault" col="IsDefault" type="hidden" />

        <div class="form-group">
            <label class="col-sm-3 control-label">类别<font class="red"> *</font></label>
            <div class="col-sm-8 " id="type" col="Type"></div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label ">编码<font class="red"> *</font></label>
            <div class="col-sm-8">
                <div>
                    <input id="code" col="Code" type="text" class="form-control" />
                    <span><i class="fa fa-info-circle"></i> 只能由英文字母和数字组成，不超过31个字符</span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">名称<font class="red"> *</font></label>
            <div class="col-sm-8">
                <input id="name" col="Name" type="text" class="form-control" />
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label ">排序码</label>
            <div class="col-sm-8">
                <input id="sequence" col="Sequence" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">状态</label>
            <div class="col-sm-8" id="status" col="Status">
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label ">描述</label>
            <div class="col-sm-8">
                <textarea id="description" col="Description" class="form-control" style="height:68px"></textarea>
            </div>
        </div>

    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    var type = ys.request("type");
    var index = ys.request("index");
    var act = 'edit';
    if (id == '' | id == null) act = 'add';

    $(function () {
        $("#status").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(StatusType).EnumToDictionaryJson())) });
        $("#type").ysComboBox({
                data: ys.getJson(@Html.Raw(typeof(CustConfigType).EnumToDictionaryJson())),
                key: "Key",
                value: "Value",
                class: "form-control",
            });
            $('#type_select').attr('disabled', 'true');


        getForm();

        $("#form").validate({
            rules: {
                index: { digits: true },
                type: { required: true },
                code: { required: true, maxlength: 23 },
                name: { required: true, maxlength: 31 },
            }
        });
    });


    function getForm() {
        if (act == 'add') {//add
            ys.ajax({
                url: '@Url.Content("~/Sys/Config/GetMaxSequenceNoJson")'+'?type='+type,
                type: "get",
                 success: function (rst) {
                     var defaultData = {};
                     defaultData.Sequence = rst.Data;
                     defaultData.Type = type;
                     defaultData.Status = "@((int)StatusType.Enabled)";
                     $("#form").setWebControls(defaultData);
                 }
            });
        }
        else {//edit
            ys.ajax({
                url: '@Url.Content("~/Sys/Config/GetEditDtoJson")' + '?id=' + id,
                type: "get",
                success: function (rst) {
                    if (rst.Flag == 1) {
                        $("#form").setWebControls(rst.Data);
                    } else {
                        ys.msgError(rst.Message);
                    }
                }
            });
        }
    }

    function saveForm(index) {
        if (!ys.checkTextLenth("description", "描述", 0, 127)) return;

        if ($("#form").validate().form()) {
            var postData = $("#form").getWebControls({ Id: id });
            ys.ajax({
                url: '@Url.Content("~/Sys/Config/")' + act,
                type: "post",
                data: postData,
                success: function (rst) {
                    if (rst.Flag == 1) {
                        ys.msgSuccess(rst.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(rst.Message);
                    }
                }
            });
        }
    }

    function leaveForm(index) {
        parent.layer.close(index);
    }


</script>
